package com.qf.topic;

import com.qf.util.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

public class Publisher {

    @Test
    public void publish() throws Exception {
        //1. connection
        Connection connection = ConnectionUtil.getConnection();
        //2. channel
        Channel channel = connection.createChannel();

        //3. declareExchange
        channel.exchangeDeclare("topic_exchange", BuiltinExchangeType.TOPIC);
        //4. declareQueue1
        channel.queueDeclare("topic_queue1",true,false,false,null);
        //5. declareQueue2
        channel.queueDeclare("topic_queue2",true,false,false,null);

        //6. bind - queue1 + exchange ~  *.orange.*
        channel. queueBind("topic_queue1","topic_exchange","*.orange.*");
        //7. bind - queue2 + exchange ~  *.*.rabbit
        channel. queueBind("topic_queue2","topic_exchange","*.*.rabbit");
        //8. bind - queue2 + exchange ~  lazy.#
        channel. queueBind("topic_queue2","topic_exchange","lazy.#");

        //9. send Message
        channel.basicPublish("topic_exchange","big.orange.rabbit",null,"大橘兔".getBytes());
        channel.basicPublish("topic_exchange","lazy.black.rabbit",null,"懒黑兔".getBytes());
    }
}
